/* 
 * Copyright (C) 2008 anphoralhrod.blogspot.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * SimpleFileTextArea.java
 *
 * Created on 14 de julio de 2008, 11:48
 */

package SimpleControl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextArea;

/**
 *
 * @author  fran
 */
public class SimpleFileTextArea extends JTextArea {
    private URL url = null;

    /** Creates new form BeanForm */
    public SimpleFileTextArea() {
        this.setLineWrap(true);
        this.setEditable(false);
        this.setAutoscrolls(true);
    }
    
    public URL getUrl()
    {
        return url;
    }
    
    public void setUrl(URL url)
    {
        String sCadena, sText;
        InputStreamReader sr = null;
        if (url != null)
        {
            this.url = url;
            try {
                sr = new InputStreamReader(url.openStream());
            } catch (IOException ex) {
                Logger.getLogger(SimpleFileTextArea.class.getName()).log(Level.SEVERE, null, ex);
            }

            sText = "";
            BufferedReader bf = new BufferedReader(sr);
            try {
                while ((sCadena = bf.readLine()) != null)
                    sText += "\n" + sCadena;
            } catch (IOException ex) {
                Logger.getLogger(SimpleFileTextArea.class.getName()).log(Level.SEVERE, null, ex);
            }
            this.setText(sText);
        }
    }

}
